﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>teacherInfo</title>
<script type="text/javascript">
	
	var mainform;
	$(function() {
		mainform=$("#mainform");
        mainform.ligerForm();
        $.metadata.setType("attr", "validate");
        LG.validate(mainform);
        
		$(".l-toolbar-item").hover(function() {
			$(this).addClass("l-panel-btn-over");
		}, function() {
			$(this).removeClass("l-panel-btn-over");
		});

		$(".l-toolbar-item").click(function() {
			toolbarBtnItemClick($(this));
		});
		
	});

	function toolbarBtnItemClick(item) {
		switch (item.attr("toolbarid")) {
		case "modifyInfo":
			var infoStr="";
			if($("#firstPwd").val()==null || $("#firstPwd").val()=="") infoStr+="原始密码,";
			if($("#newPwd").val()==null || $("#newPwd").val()=="") infoStr+="新密码,";
			if($("#thirdPwd").val()==null || $("#thirdPwd").val()=="") infoStr+="确认密码,";
			if(infoStr!=""){
				LG.showError('错误:' + infoStr+'不能为空');
			}else{
				if($("#newPwd").val()!=$("#thirdPwd").val()){
					$.ligerDialog.confirm("新密码两次输入不一致",function (yes) {
						if(yes){
							$("#newPwd").val("");
							$("#thirdPwd").val("");
						}
					});
				}else{
					var str=$("#firstPwd").val();
					$.ajax({
		                type: 'post', cache: false, dataType: 'json',
		                url: '${ctx}/user/isExitUser',
		                data: [
		                { name: 'userId', value: '' },
		                { name: 'password', value: str }
		                ],
		                success: function (result){
		                	
		                	if(typeof(result)=="string"){
		                		result=eval("("+result+")");
		                	}
		                    if (!result.success){
		                        alert(result.message);
		                        return;
		                    } else{
		                    	LG.submitForm(mainform, function (result) {
		        		        	if(typeof(result)=="string"){
		        		        		result=eval("("+result+")");
		        		        	}
		        		            if (!result.success) {
		        		                LG.showError('错误:' + result.message);
		        		            }
		        		            else { 
		        		                LG.showSuccess('保存成功', function () { 
		        		                	var win = window.parent || window;
		        		                    if(win.dialog){
		        		                    	win.dialog.close();
		        		                    }
		        		                });
		        		            }
		        		        });
		                    }
		                },
		                error: function (){
		                    alert('系统错误,请与系统管理员联系!');
		                }
		            });
					
				}
			}
			
			break;
		case "modifyPwd":
			var win = window.parent || window;
	        if(win.dialog){
	        	win.dialog.close();
	        }
			break;
		}
	}
</script>
</head>
<body style="padding: 0px; overflow: hidden;">
	<c:if test="${!empty error} }">
		<label style="color: red;left: 20px">${error}</label>
	</c:if>
	<form name="mainform" method="post" id="mainform" action="${ctx }/user/update">
		<input name="userType" id="userType" type="hidden" value="tea">
		<table cellpadding="0" cellspacing="0" class="l-table-edit"
			style="width: 90%; margin-top: 10px; margin-left: 15px;">
			<tr>
				<td align="right" class="l-table-edit-td" style="width: 35%;">旧密码:</td>
				<td align="left" class="l-table-edit-td" style="width: 35%;"><input
					name="firstPwd" type="text" id="firstPwd"  ltype="text" validate="{required:true}" />
				</td>
			</tr>
			<tr>
				<td align="right" class="l-table-edit-td" style="width: 35%;">新密码:</td>
				<td align="left" class="l-table-edit-td" style="width: 35%;"><input
					name="newPwd" type="password" id="newPwd"  ltype="text"  validate="{required:true}"/>
				</td>
			</tr>
			
			<tr>
				<td align="right" class="l-table-edit-td" style="width: 35%;">请再输一遍:</td>
				<td align="left" class="l-table-edit-td" style="width: 35%;"><input
					name="thirdPwd" type="password" id="thirdPwd"  ltype="text" validate="{required:true}" /></td>
			</tr>
			<tr>
				<td colspan="3"></td>
				<td align="right"  colspan="2">
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon"
						toolbarid="modifyInfo">
						<span>确定</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
						<img src="${ctx}/static/icons/silkicons/application_edit.png">
					</div>
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon"
						toolbarid="modifyPwd">
						<span>取消</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
						<img src="${ctx}/static/icons/silkicons/application_edit.png">
					</div>
				</td>
			</tr>
		</table>
	</form>

	<div style="display: none;"></div>

</body>
</html>
